

//
//  MenuView.m
//  BusinessMarket
//
//  Created by Michael Li on 2018/11/28.
//  Copyright © 2018年 Michael Li. All rights reserved.
//

#import "MenuView.h"
#import "UIView+ZF.h"
#import "ShowCollectionCell.h"
#import "HomeModel.h"
#import "MenuCell.h"
#import "MenuTableView.h"
#import "MenuProvinceView.h"
#import "MenuCenterCell.h"
#import "MenuCityView.h"
#import "MenuUsuallyView.h"
#define kLineW 0
#define kLineH 25.f
#define kRowH 44
#define kDefTitleCor [UIColor colorWithRed:159/255.0 green:159/255.0 blue:159/255.0 alpha:1]
#define KPlaceHeight kUIScreen.size.height*0.6
#define frameDefault CGRectMake(0, self.navigationHeight + self.h, self.w, KPlaceHeight)
#define frameHalfLeftZero CGRectMake(0, self.navigationHeight + self.h, self.w/2, 0)
#define frameHalfLeft CGRectMake(0, self.navigationHeight + self.h, self.w/2, KPlaceHeight)
#define frameHalfRightZero CGRectMake(self.w/2, self.navigationHeight + self.h, self.w/2, 0)
#define frameHalfRight CGRectMake(self.w/2, self.navigationHeight + self.h, self.w/2, KPlaceHeight)
#define frameThirdLeftZero CGRectMake(0, self.navigationHeight + self.h, self.w/3, 0)
#define frameThirdLeft CGRectMake(0, self.navigationHeight + self.h, self.w/3, KPlaceHeight)
#define frameThirdCenterZero CGRectMake(self.w/3, self.navigationHeight + self.h, self.w/3, 0)
#define frameThirdCenter CGRectMake(self.w/3, self.navigationHeight + self.h, self.w/3, KPlaceHeight)
#define frameThirdRightZero CGRectMake(self.w/3*2, self.navigationHeight + self.h, self.w/3, 0)
#define frameThirdRight CGRectMake(self.w/3*2, self.navigationHeight + self.h, self.w/3, KPlaceHeight)
@interface MenuView()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,ShowCollectionCellDelegate,UITableViewDelegate, UITableViewDataSource>
@property(nonatomic,strong) MCButton *btn;
@property(nonatomic,strong) UIButton *preBtn;
@property(nonatomic,strong) UIView  *superView;
@property(nonatomic,strong) UICollectionView *collectionView;
@property(nonatomic,strong) MenuTableView *menuTabView;
@property(nonatomic,strong) MenuProvinceView *menuProvinceView;
@property(nonatomic,strong) MenuCityView *menuCityView;
@property(nonatomic,strong) MenuUsuallyView *usuallyView;
@property(nonatomic,assign) NSInteger index;
@property(nonatomic,assign) NSInteger preInterger;
@property(nonatomic,assign) NSInteger preRow;
@property(nonatomic,strong) NSMutableArray *dataMuta;
@property(nonatomic,strong) NSString *cityNamed;
@property(nonatomic,strong) HomeModel *allModel;
@property(nonatomic,strong) HomeModel *usuallyModel;
@property(nonatomic,strong) HomeModel *cityModel;
//@property(nonatomic,strong) NSMutableArray *proviceMutb;
//@property(nonatomic,strong) NSMutableArray *cityMutb;
@end
@implementation MenuView
static NSString *identifier = @"ShowCollectionCell";
static NSString *identifierMenuCell = @"menuCell";
static NSString *identifierMenuCenterCell = @"menuCenterCell";

-(NSMutableArray *)dataMuta
{
    if (!_dataMuta) {
        _dataMuta = [NSMutableArray array];
    }
    return _dataMuta;
}
-(UIView *)superView
{
    if (!_superView) {
        _superView = [[UIView alloc]initWithFrame:CGRectMake(0, self.navigationHeight + self.h, kUIScreen.size.width, kUIScreen.size.height)];
        [self.superView.window addSubview:_superView];
        _superView.backgroundColor = [UIColor colorWithWhite:0.1 alpha:0.8];
//        _superView.backgroundColor = [UIColor whiteColor];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(shadowViewClick)];
        [_superView addGestureRecognizer:tap];
        
    }
    return _superView;
}
#pragma mark-代理:常用地区
-(MenuUsuallyView *)usuallyView
{
    if (!_usuallyView) {
        _usuallyView = [[MenuUsuallyView alloc]initWithFrame:frameHalfRightZero];
//        _usuallyView.h = 0;
    }
    return _usuallyView;
}
#pragma mark-代理:省
-(MenuProvinceView *)menuProvinceView
{
    if (!_menuProvinceView) {
        _menuProvinceView = [[MenuProvinceView alloc]initWithFrame:frameHalfRightZero];
    }
    return _menuProvinceView;
}
#pragma mark-代理:市
-(MenuCityView *)menuCityView
{
    if (!_menuCityView) {
        _menuCityView = [[MenuCityView alloc]initWithFrame:frameHalfRightZero];
    }
    return _menuCityView;
}
#pragma mark - 点击背景
- (void)shadowViewClick
{
    [self hideListViewAnimation];
    [self resetStatus:self.btn];
}
- (UICollectionView *)collectionView
{
    
    if (!_collectionView) {
        UICollectionViewFlowLayout *flowe = [[UICollectionViewFlowLayout alloc]init];
        CGRect frame = CGRectMake(0.f,self.navigationHeight + self.h, self.w, 0.f);
        //XLog(@"navigationHeight:%ld",(long)self.navigationHeight);
        flowe.minimumLineSpacing = 0;
        flowe.minimumInteritemSpacing = 0;
        _collectionView = [[UICollectionView alloc] initWithFrame:frame collectionViewLayout:flowe];
        _collectionView.backgroundColor = [UIColor whiteColor];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        [_collectionView registerClass:[ShowCollectionCell class]
            forCellWithReuseIdentifier:identifier];
        
    }
    return _collectionView;
}
- (MenuTableView *)menuTabView
{
    if (!_menuTabView) {
        CGRect frame = CGRectMake(0.f, self.navigationHeight + self.h, self.w, 0.f);
        XLog(@"self.navigationHeight + self.h:%f",(long)self.navigationHeight + self.h);
        _menuTabView = [[MenuTableView alloc] initWithFrame:frame style:UITableViewStylePlain];
        _menuTabView.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero];
        _menuTabView.delegate = self;
        _menuTabView.dataSource = self;
        _menuTabView.backgroundColor = [UIColor whiteColor];
//        [_menuTabView registerClass:[MenuCell class] forCellReuseIdentifier:identifierMenuCell];
        [_menuTabView registerNib:[UINib nibWithNibName:@"MenuCenterCell" bundle:nil] forCellReuseIdentifier:identifierMenuCenterCell];
    }
    return _menuTabView;
}

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        self.allModel = [[HomeModel alloc]init];
        self.usuallyModel = [[HomeModel alloc]init];
        self.cityModel = [[HomeModel alloc]init];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(placeselectList:) name:@"placeselectList" object:nil];
         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(hiddenMenuView:) name:@"hiddenMenuView" object:nil];
    }
    return self;
}
-(void)hiddenMenuView:(NSNotification *)info
{
    [self hideListViewAnimation];
}

-(void)placeselectList:(NSNotification *)info
{
    NSDictionary *dict = info.userInfo;
    XLog(@"dict:%@",dict);
    NSArray *date = [dict objectForKey:@"date"];
    for (NSDictionary *dict in date) {
        HomeModel*model = [HomeModel mj_objectWithKeyValues:dict];
        [self.dataMuta addObject:model];
    }
}
-(void)dealloc
{
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}
-(void)setTitles:(NSArray *)titles
{
    XLog(@"titles:%@",titles);
    for (int i = 0; i < titles.count; i++) {
        CGFloat buttonW = (self.w - (titles.count-1)*kLineW)/titles.count;
        CGFloat buttonH = self.frame.size.height;
        CGFloat buttonX = (buttonW+kLineW) * i;
        CGRect btnFrame = CGRectMake(buttonX, 0.f, buttonW, buttonH);
        self.btn = [[MCButton alloc]initWithFrame:btnFrame];
        [self addSubview:self.btn];
        self.btn.buttonStyle = imageRight;
        UIImage *imageNor = [UIImage imageNamed:@"icon_160"];
        UIImage *imageHig = [UIImage imageNamed:@"icon_157"];
        [self.btn setImage:imageNor forState:UIControlStateNormal];
        [self.btn setImage:imageHig forState:UIControlStateSelected];
        [self.btn setTitle:titles[i] forState:UIControlStateNormal];
        [self.btn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
        self.btn.backgroundColor = [UIColor whiteColor];
        self.btn.tag = i+1;
        self.btn.titleLabel.font = [UIFont systemFontOfSize:14];
//        [self.btn setTitleColor:[UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1] forState:UIControlStateNormal];
        [self.btn setTitleColor:kDefTitleCor forState:UIControlStateNormal];
        [self.btn setTitleColor:kOrangeBg forState:UIControlStateSelected];
//        self.btn.highlighted = NO;
    }
}
#pragma mark-代理:CollectionCell
- (void)showCollectionCell:(ShowCollectionCell *)showCollectionCell withBtn:(nonnull MCButton *)btn
{
}
#pragma mark-代理:点击条件选择
-(void)clickBtn:(UIButton *)btn
{
    btn.selected = !btn.selected;
    UIView *superView = self.superview;
    [superView.window addSubview:self.superView];
    [superView.window addSubview:self.collectionView];
    [superView.window addSubview:self.menuTabView];
    [superView.window addSubview:self.usuallyView];
    [superView.window addSubview:self.menuProvinceView];
    [superView.window addSubview:self.menuCityView];
    
    if (self.preBtn != btn) {
        self.preBtn.selected = NO;
        [self.preBtn setTitleColor:kDefTitleCor forState:UIControlStateNormal];
    }else {
    }
    if (btn.selected) {
        if (btn.tag == 1) {
            self.dataArray = self.oneArray;
            self.menuProvinceView.frame = frameHalfRightZero;
            self.menuCityView.frame = frameHalfRightZero;
            [self.collectionView reloadData];
        }else if (btn.tag == 2) {
            self.dataArray = self.twoArray;
            [self.menuTabView reloadData];
        }else if (btn.tag == 3) {
            self.dataArray = self.threeArray;
            [self.menuTabView reloadData];
            [self.usuallyView reloadData];
        }else {
            self.dataArray = self.fourArray;
            [self.menuTabView reloadData];
        }
        self.index = btn.tag;
        self.btn = (MCButton *)[self viewWithTag:self.index];
        [self showListViewAnimation];
        
    }else {
        [self hideListViewAnimation];
    }
    self.preBtn = btn;
}
- (void)resetStatus:(UIButton *)button
{
    for (id oc in self.subviews) {
        if ([oc isKindOfClass:[UIButton class]]) {
            UIButton *btn = (UIButton *)oc;
            btn.selected = NO;
            
//            UIImage *imageNor = [UIImage imageNamed:@"ic_home_wallet_date_datemore"];
//            UIImage *imageHig = [UIImage imageNamed:@"ic_news_up-1"];
            if ([[btn currentTitle]isEqualToString:@"行业"]||[[btn currentTitle]isEqualToString:@"类型"]||[[btn currentTitle]isEqualToString:@"地区"]||[[btn currentTitle]isEqualToString:@"排序"]) {
//                [btn setImage:imageHig forState:UIControlStateNormal];
                [btn setTitleColor:kDefTitleCor forState:UIControlStateNormal];
            }else {
                [btn setTitleColor:kOrangeBg forState:UIControlStateNormal];
            }

        }

    }

}
-(void)showListViewAnimation
{
    self.superView.hidden = NO;
    if (self.index == 1) {
        self.collectionView.h = [self maxCollectionListHeightWithModel:self.dataArray];
        self.menuTabView.h = 0;
        self.usuallyView.h = 0;
        self.usuallyView.frame = frameHalfRightZero;
        self.menuProvinceView.h = 0;
        self.menuCityView.h = 0;
    }else {
        self.collectionView.h = 0;
        self.menuTabView.h = [self maxMenuTabViewHeightWithModel:self.dataArray];
        self.menuTabView.w = self.w;
        
        if (self.index == 2||self.index == 4) {
            self.usuallyView.frame = frameHalfRightZero;
            self.usuallyView.h = 0;
            self.menuProvinceView.frame = frameThirdCenterZero;
            self.menuProvinceView.h = 0;
            self.menuCityView.frame = frameThirdRightZero;
            self.menuCityView.h = 0;
        }else if (self.index == 3) {
            if (self.allModel.show) {
                self.menuTabView.frame = frameDefault;
                self.menuTabView.h = [self maxMenuTabViewHeightWithModel:self.dataArray];
                self.usuallyView.frame = frameHalfRightZero;
                self.usuallyView.h = 0;
                self.menuProvinceView.frame = frameThirdCenterZero;
                self.menuProvinceView.h = 0;
                self.menuCityView.frame = frameThirdRightZero;
                self.menuCityView.h = 0;
                HomeModel *allModel = self.dataArray[0];
                HomeModel *model = self.dataArray[1];
                HomeModel *modelPre = self.dataArray[2];
                self.preRow = 0;
                allModel.show = YES;
                modelPre.show = NO;
                model.show = NO;
            }
            if (self.usuallyModel.show) {//常用地区
                self.menuTabView.frame = frameHalfLeft;
                self.usuallyView.h = KPlaceHeight;
                self.menuProvinceView.frame = frameThirdCenterZero;
                self.menuProvinceView.h = 0;
                self.menuCityView.frame = frameThirdRightZero;
                self.menuCityView.h = 0;
                HomeModel *model = self.dataArray[1];
                HomeModel *modelPre = self.dataArray[2];
                self.preRow = 1;
                modelPre.show = NO;
                model.show = YES;
            }
            if (self.cityModel.show) {//省市
                self.menuTabView.frame = frameThirdLeft;
                self.menuTabView.h = KPlaceHeight;
                self.menuProvinceView.frame = frameThirdCenter;
                self.menuProvinceView.w = self.w/3;
                self.menuProvinceView.h = KPlaceHeight;
                self.menuCityView.frame = frameThirdRight;
                self.menuCityView.h = KPlaceHeight;
                self.usuallyView.frame = frameHalfRightZero;
                self.usuallyView.h = 0;
                self.preRow = 2;
                HomeModel *model = self.dataArray[1];
                HomeModel *modelPre = self.dataArray[2];
                modelPre.show = YES;
                model.show = NO;
                [self.menuProvinceView reloadData];
                [self.menuCityView reloadData];
            }
            if (!self.allModel.show&&!self.usuallyModel.show&&!self.cityModel.show) {
                self.menuTabView.frame = frameDefault;
                self.menuTabView.h = [self maxMenuTabViewHeightWithModel:self.dataArray];
                self.usuallyView.frame = frameHalfRightZero;
                self.usuallyView.h = 0;
                self.menuProvinceView.frame = frameThirdCenterZero;
                self.menuProvinceView.h = 0;
                self.menuCityView.frame = frameThirdRightZero;
                self.menuCityView.h = 0;
                HomeModel *allModel = self.dataArray[0];
                HomeModel *model = self.dataArray[1];
                HomeModel *modelPre = self.dataArray[2];
                self.preRow = 0;
                allModel.show = NO;
                modelPre.show = NO;
                model.show = NO;
            }
        }
    }
}
-(void)hideListViewAnimation
{
    self.collectionView.h = 0;
    self.menuTabView.h = 0;
    self.superView.hidden = YES;
    self.menuProvinceView.h = 0;
    self.menuCityView.h = 0;
    self.usuallyView.h = 0;
    [self.collectionView removeFromSuperview];
    [self.menuTabView removeFromSuperview];
    [self.superView removeFromSuperview];
    [self.usuallyView removeFromSuperview];
    [self.menuProvinceView removeFromSuperview];
    [self.menuCityView removeFromSuperview];
    [self resetStatus:self.btn];
}
// 更具数据源里边数据情况，返回TableView高度
- (CGFloat)maxCollectionListHeightWithModel:(NSArray *)dataSource
{
//    CGFloat height = (dataSource.count /3+1)*kRowH;
    CGFloat height = (dataSource.count/3+1)*kRowH+10;
    return height;
}
// 更具数据源里边数据情况，返回TableView高度
- (CGFloat)maxMenuTabViewHeightWithModel:(NSArray *)dataSource
{
    
    CGFloat height = dataSource.count*kRowH;
    return height;
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.dataArray.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    ShowCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
    cell.delegate = self;
//    cell.cellLabel.layer.cornerRadius = 15;
    cell.indexPath = indexPath;
    if (self.index == 1) {
        HomeModel *model = self.dataArray[indexPath.row];
        cell.homeModel = model;
    }
    return cell;
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    [self hideListViewAnimation];
//    XLog(@"interger:%ld",btn.tag);
    HomeModel *model = self.dataArray[indexPath.row];
    model.show = YES;
    if (self.preInterger != indexPath.row) {
        HomeModel *preModel = self.dataArray[self.preInterger];
        preModel.show = NO;
        
    }
    XLog(@"indexPath.row:%ld",indexPath.row);
    XLog(@"indexPath.row:%ld",indexPath.row);
    self.preInterger = indexPath.row;
    [self resetStatus:self.btn];
    self.btn = (MCButton *)[self viewWithTag:self.index];
//    ShowCollectionCell *cell = (ShowCollectionCell *)[collectionView cellForItemAtIndexPath:indexPath];
    [self.btn setTitle:model.content forState:UIControlStateNormal];
//    cell.cellLabel.text = model.content;
//    self.btn.selected = NO;
    [self.btn setTitleColor:kOrangeBg forState:UIControlStateNormal];
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setValue:model.content forKey:@"industry"];
    if (self.searchIndex == 0) {
        NSNotification *notification = [NSNotification notificationWithName:@"serviceHallSearchIndustry" object:nil userInfo:dict];
        [[NSNotificationCenter defaultCenter]postNotification:notification];
        
    }else {
        NSNotification *notification = [NSNotification notificationWithName:@"functionIndustry" object:nil userInfo:dict];
        [[NSNotificationCenter defaultCenter]postNotification:notification];
    }
    [self.collectionView reloadData];
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.index == 1) {
        return CGSizeMake(kWidth/3, kRowH);
    }else if (self.index == 2) {
        return CGSizeMake(kWidth, kRowH);
    }else if (self.index == 3) {
        return CGSizeMake(kWidth, kRowH);
    }else {
        return CGSizeMake(kWidth, kRowH);
    }
    
}
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return kRowH;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    MenuCenterCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierMenuCenterCell forIndexPath:indexPath];
    
    cell.indexPath = indexPath;
    if (self.index != 1) {
        HomeModel *model = self.dataArray[indexPath.row];
        cell.homeModel = model;
        if (self.index == 3&&indexPath.row==1) {
//            if (model.show) {
//                self.usuallyView.h = KPlaceHeight;
//            }else {
//                self.usuallyView.h = 0;
//            }
        }
    }
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    HomeModel *model = self.dataArray[indexPath.row];
    HomeModel *modelPre = self.dataArray[self.preRow];
    if (self.preRow == indexPath.row) {
    }else {
        modelPre.show = NO;
    }
    model.show = YES;
    XLog(@"self.preRow:%ld",self.preRow);
    self.preRow = indexPath.row;
    [self.menuTabView reloadData];
    if (![model.content isEqualToString:@"常用地区"]&&![model.content isEqualToString:@"省/直辖市"]) {
        [self.btn setTitle:model.content forState:UIControlStateNormal];
    }
    XLog(@"model.content:%@",model.content);
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    if (self.index == 2) {//类型
        NSString *types = [NSString stringWithFormat:@"%ld",indexPath.row];
        [dict setValue:types forKey:@"type"];
        if (self.searchIndex == 0) {//服务大厅
            NSNotification *notification = [NSNotification notificationWithName:@"serviceHallSearchType" object:nil userInfo:dict];
            [[NSNotificationCenter defaultCenter]postNotification:notification];
        }else {//首页搜索
            NSNotification *notification = [NSNotification notificationWithName:@"serviceFunctionSearchType" object:nil userInfo:dict];
            [[NSNotificationCenter defaultCenter]postNotification:notification];
        }
        [self hideListViewAnimation];
    }else  if (self.index == 3) {//地区
        if (indexPath.row == 0) {//全国不限
            self.usuallyView.frame = frameHalfRightZero;
            self.menuProvinceView.frame = frameThirdCenterZero;
            self.menuCityView.frame = frameThirdRightZero;
            [dict setValue:model.content forKey:@"address"];
            if (self.searchIndex == 0) {
                NSNotification *notification = [NSNotification notificationWithName:@"serviceHallSearchAddress" object:nil userInfo:dict];
                [[NSNotificationCenter defaultCenter]postNotification:notification];
                
            }else {
                NSNotification *notification = [NSNotification notificationWithName:@"serviceFunctionSearchAddress" object:nil userInfo:dict];
                [[NSNotificationCenter defaultCenter]postNotification:notification];
            }
            self.allModel.show = YES;
            self.usuallyModel.show = NO;
            self.cityModel.show = NO;
            [self.menuCityView reloadData];
//            NSNotification *notification = [NSNotification notificationWithName:@"cityShow" object:nil];
//            [[NSNotificationCenter defaultCenter]postNotification:notification];
            [self hideListViewAnimation];
        }else if (indexPath.row == 1) {//常用地区
            self.menuProvinceView.frame = frameThirdCenterZero;
            self.menuProvinceView.h = 0;
            self.menuCityView.frame = frameThirdRightZero;
            self.menuCityView.h = 0;
            self.menuTabView.frame = frameHalfLeft;
            self.usuallyView.frame = frameHalfRight;
            self.usuallyView.h = KPlaceHeight;
            XLog(@"self.usuallyView.frame:%@",NSStringFromCGRect(self.usuallyView.frame));
            __weak typeof (self)weakSelf = self;
            self.usuallyView.returnValueBlock = ^(NSString * _Nonnull cellNamed) {
                [weakSelf.btn setTitle:cellNamed forState:UIControlStateNormal];
//                [weakSelf hideListViewAnimation];
//                [weakSelf.usuallyView removeFromSuperview];
                [dict setValue:cellNamed forKey:@"address"];
                if (self.searchIndex == 0) {
                    NSNotification *notification = [NSNotification notificationWithName:@"serviceHallSearchAddress" object:nil userInfo:dict];
                    [[NSNotificationCenter defaultCenter]postNotification:notification];
                    
                }else {
                    NSNotification *notification = [NSNotification notificationWithName:@"serviceFunctionSearchAddress" object:nil userInfo:dict];
                    [[NSNotificationCenter defaultCenter]postNotification:notification];
                }
                weakSelf.allModel.show = NO;
                weakSelf.usuallyModel.show = YES;
                weakSelf.usuallyView.usuallyShow = YES;
                weakSelf.menuProvinceView.provinceShow = NO;
                weakSelf.cityModel.show = NO;
                [weakSelf hideListViewAnimation];
            };
        }else {//省市
            
            self.usuallyView.frame = frameHalfRightZero;
            self.menuTabView.frame = frameHalfLeft;
            self.menuProvinceView.frame = frameHalfRight;
            self.menuProvinceView.h = KPlaceHeight;
            self.menuProvinceView.w = self.w/2;
            self.menuCityView.frame = frameThirdRightZero;
            self.menuCityView.h = 0;
            self.menuProvinceView.provinceShow = NO;
            [self.menuProvinceView reloadData];
            __weak typeof (self)weakSelf = self;
            self.menuProvinceView.returnValueBlock = ^(NSInteger cityRow, NSString * _Nonnull cellNamed) {
                weakSelf.menuTabView.frame = frameThirdLeft;
                weakSelf.menuProvinceView.frame = frameThirdCenter;
                weakSelf.menuProvinceView.w = self.w/3;
                weakSelf.menuCityView.frame = frameThirdRight;
                weakSelf.menuCityView.h = KPlaceHeight;
                weakSelf.menuCityView.w = self.w/3;
                weakSelf.menuCityView.index = cityRow;
                weakSelf.menuProvinceView.provinceShow = YES;
                [weakSelf.menuCityView reloadData];
                weakSelf.menuCityView.returnValueBlock = ^(NSInteger row, NSString * _Nonnull cellNamed) {
                    weakSelf.menuCityView.cityNamed = cellNamed;
                    XLog(@"weakSelf.index:%ld",weakSelf.index);
                    XLog(@"cellNamed:%@",cellNamed);
                    [weakSelf.btn setTitle:cellNamed forState:UIControlStateNormal];
                    [dict setValue:cellNamed forKey:@"address"];
                    if (self.searchIndex == 0) {
                        NSNotification *notification = [NSNotification notificationWithName:@"serviceHallSearchAddress" object:nil userInfo:dict];
                        [[NSNotificationCenter defaultCenter]postNotification:notification];
                    }else {
                        NSNotification *notification = [NSNotification notificationWithName:@"serviceFunctionSearchAddress" object:nil userInfo:dict];
                        [[NSNotificationCenter defaultCenter]postNotification:notification];
                    }
                    weakSelf.menuCityView.preIndex = cityRow;
                    weakSelf.usuallyView.usuallyShow = NO;
                    weakSelf.allModel.show = NO;
                    weakSelf.usuallyModel.show = NO;
                    weakSelf.cityModel.show = YES;
                    [weakSelf hideListViewAnimation];
                };
            };

        }
    }else  if (self.index == 4) {//排序
        NSMutableDictionary *dict = [NSMutableDictionary dictionary];
        NSString *types = [NSString stringWithFormat:@"%ld",indexPath.row];
        [dict setValue:types forKey:@"order"];
         if (self.searchIndex == 0) {
             NSNotification *notification = [NSNotification notificationWithName:@"serviceHallSearchOrder" object:nil userInfo:dict];
             [[NSNotificationCenter defaultCenter]postNotification:notification];
         }else {
             NSNotification *notification = [NSNotification notificationWithName:@"serviceFunctionSearchOrder" object:nil userInfo:dict];
             [[NSNotificationCenter defaultCenter]postNotification:notification];
         }
        [self hideListViewAnimation];
    }

}
@end
